<template>
	<view class="padb10">
		<stop isBack>
			<view slot="content">巡检计划</view>
		</stop>
		<view class="mart3">
			<!-- <stab @change="(index)=>{curTab=index}" :names="['计划信息','绑定设备','任务列表']"></stab> -->
			<stab @change="(index)=>{curTab=index}" :names="['计划信息','绑定设备']"></stab>
		</view>
		<view v-if="isbool(en)">
			<view class="padlr3" v-show="curTab == 0">
				<view class="lh2 bcf pad2 bdtso mart3">
					<view class="list-style-2 flrc">
						<view class="flex1">巡检计划信息</view>
					</view>
					<view class="mart3">
						<check-plan :item="en" v-if="isbool(en.id)"></check-plan>
					</view>
				</view>
			</view>
			<view class="padlr3" v-show="curTab == 1">
				<view class="lh2 bcf pad2 bdtso mart3">
					<view class="list-style-2 flrc">
						<view class="flex1">关联设备</view>
					</view>
				
					<!-- 显示选择的设备 -->
					<view class="pad3 bdso bcf mart3" v-show="isbool(en.machines)">
						<view class="pad1 mart3 pos-r ofh bc13 round3" @tap="mySlide(index)" 
						v-for="machine,index in en.machines" :key="machine.id" >
							<machine-item class="w100" :itemId="machine.id"></machine-item>
						</view>
						
					</view>
				</view>
			</view>
			<view class="padlr3" v-show="curTab == 2">
				<view class="lh2 bcf pad2 bdtso mart3">
					<view class="list-style-2 flrc">
						<view class="flex1">计划情况</view>
					</view>
					<!-- {{en}} -->
					<view >
						<view class="mart4 bdso pad2" v-for="planlistItem in en.planLists">
							<!-- {{planlistItem}} -->
							<view class="bcf">
								<plan-list :item="planlistItem"></plan-list>
							</view>
							<view class="bc13 mart2">
								<machine-item class="w100" :item="planlistItem.machine"></machine-item>
							</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<loading :loading="myIsLoading"></loading>
		<machine-selector :show="showSelectListMachine" @onSelect="selectMachine"></machine-selector>
		
	<!-- 	<view class="lh2 bcf pad2 bdtso pos-a l0 r0 b0">
			<view class="tac pad2 line-green round cu-btn lg w100 " @tap="submit">
				<view>提交</view>
				<ripple></ripple>
			</view>
		</view> -->
	</view>
</template>

<script>
	import machineItem from '../../templete/machine/machine_item.vue'
	import machineSelector from '../../templete/machine/machine_selector.vue'
	import MescrollCompMixin from "@/components/mescroll-uni/mixins/mescroll-comp.js";
	import checkPlan from '../../templete/machine/machine_plan_check_item.vue'
	import planList from '../../templete/machine/machine_plan_list_item.vue'
	
	export default {
		// mixins:[MescrollCompMixin],
		components:{machineItem,machineSelector,checkPlan,planList},
		data() {
			return {
				curTab:0,
				id:"",
				en:{},
				showSelectListMachine:true,
				showSelectedMachine:true,
				selectedMachine:{
					id:'',
					code:'',
					iri:''
				},
				sslide:[]
			}
		},
		methods: {
			showSelectMachine(){
				this.showSelectListMachine = Math.random()
			},
			selectMachine(val){
				if(!this.$com.isInArray(val,this.en.machines)){
					this.en.machines.push(val)
				}else{
					this.$com.showToast('该设备已存在')
				}
			},
			scanMachine(){
				this.$dev.scan(info=>{
					this.selectedMachine.code = info
				},(err)=>{
				})
			},
			deleteMachine(index){
				this.en.machines.splice(index,1);
			},
			submit(){
				this.log(this.en)
				//检查数据
				// id:'',
				// type:'',
				// day:"0",
				// startAt:'',
				// info:'',
				// department:'',
				// manageBy:'',
				// machines:[]
				if(this.isnull(this.en.machines)){this.$com.showToast('选择设备');return;}
				if(this.isnull(this.en.type)){this.$com.showToast('请选择类型');return;}
				if(this.isnull(this.en.startAt)){this.$com.showToast('请选开始时间');return;}
				if(this.isnull(this.en.info)){this.$com.showToast('请填写计划描述');return;}
				if(this.isnull(this.en.department)){this.$com.showToast('选择相关部门');return;}
				if(this.isnull(this.en.manageBy)){this.$com.showToast('选择相关人员');return;}
				this.$api.put("/api/machinePlanChecks",this.en,(res)=>{
					this.log(res)
					if(res.s == 1){
						this.goback()
					}
				})
			}
		},
		onLoad(option) {
			this.id = option.id
			// this.en.id = option.id
			if(this.isbool(this.id)){
				this.$api.get("/api/machinePlanChecks/" + this.id, {},res=>{
					this.log(res)
					this.clearLoading()
					this.en = res.d
				})
			}
		}
	}
</script>

<style>

</style>
